package com.int_tech.MessageCodeAll.dao;

import com.int_tech.MessageCodeAll.entity.CodeA2Double;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;

/**
 * Created by liubochao on 2018/7/12.
 */
public interface CodeA2DoubleDao extends JpaRepository<CodeA2Double,Integer> {
    Page<CodeA2Double> findByCarNumberAndCreatedTimeBefore(Pageable pageRequest, String carNumber, Date createdTime);

//    @Query("select c from CodeA2Double c where c.carNumber=?1 and c.createdTime<=?2 order by c.createdTime desc,c.dataString desc ")
    @Query("select c from CodeA2Double c where c.carNumber=?1 and c.createdTime<=?2 order by c.id desc ")
    Page<CodeA2Double> findByCarNumberAndCreatedTimeBeforeOrderByCreatedTimeDesc(String carNumber, Date createdTime,Pageable pageRequest);

    Page<CodeA2Double> findByCarNumberAndCreatedTimeAfterOrderByCreatedTimeAsc(Pageable pageRequest2, String carNumber, Date createTime);

    Page<CodeA2Double> findByCarNumberAndOpenStatusAndCreatedTimeAfterOrderByCreatedTimeAsc(Pageable pageRequest2, String carNumber, int i, Date startCloseDoorTime);

    Page<CodeA2Double> findByCarNumberAndOpenStatusAndCreatedTimeBeforeOrderByCreatedTimeDesc(Pageable pageRequest2, String carNumber, int i, Date createdTime);

    List<CodeA2Double> findByCarNumberAndCreatedTime(String carNumber, Date startTime);

    List<CodeA2Double> findByCheckStatus(int i);

    List<CodeA2Double> findByCheckStatusAndCarNumber(int i, String s);

    @Query("select c from CodeA2Double c where c.carNumber =?1 and c.location like CONCAT('%',?2,'%')")
    List<CodeA2Double> findByCarNumberAndLocationLike(String s, String outStation);

    @Query("select c from CodeA2Double c where c.location like CONCAT('%',?1,'%')")
    List<CodeA2Double> findByLocationLike(String outStation);

    List<CodeA2Double> findByCarNumberAndCreatedTimeAndLatAndLng(String carNumber, Date createdTime, String lat, String lng);

    List<CodeA2Double> findByCarNumber(String s);

    CodeA2Double findByDataString(String dataString);

    Page<CodeA2Double> findByCarNumberAndTimePlusGreaterThanAndOpenStatusAndCreatedTimeBeforeOrderByCreatedTimeDesc(Pageable pageRequest2, String carNumber, int i, int i1, Date createdTime);

    Page<CodeA2Double> findByCarNumberAndTimePlusGreaterThanAndOpenStatusAndCreatedTimeBeforeAndCreatedTimeAfterOrderByCreatedTimeDesc(Pageable pageRequest2, String carNumber, int i, int i1, Date createdTime, Date createTime);

    @Query("select c from CodeA2Double c where c.carNumber=?1 and c.createdTime<?2 order by c.createdTime desc ")
    Page<CodeA2Double> findByctBefore(String carNumber, Date createdTime, Pageable pageRequest1);

    @Query("select c from CodeA2Double c where c.carNumber=?1 and c.createdTime<?2 and c.openStatus=?3 order by c.createdTime desc ")
    Page<CodeA2Double> findByctBeforeAndOpenStatus(String carNumber, Date createdTime, int i, Pageable pageRequest1);

    @Query("select c from CodeA2Double c where c.carNumber=?1 and c.createdTime<?2 and c.openStatus=?3 and c.timePlus>?4 order by c.createdTime desc ")
    Page<CodeA2Double> findByctBeforeAndOpenStatusAndTimePlus(String carNumber, Date createdTime, int i, float i1, Pageable pageRequest1);

    @Query("select c from CodeA2Double c where c.carNumber=?1 and c.createdTime>?2 and c.openStatus=?3 and c.timePlus>?4 order by c.createdTime asc ")
    Page<CodeA2Double> findByctAfterAndOpenStatusAndTimePlus(String carNumber, Date createdTime, int i, float i1, Pageable pageRequest1);

    List<CodeA2Double> findByStatus(int i);

    @Query("select c from CodeA2Double c where c.carNumber=?1 and c.createdTime>?2 and c.openStatus=?3 order by c.createdTime asc ")
    Page<CodeA2Double> findByctAfterAndOpenStatus(String carNumber, Date createdTime, int i, Pageable pageRequest1);

//    Page<CodeA2Double> findByCarNumberAndCreatedTimeBefore(Pageable pageRequest2, String carNumber, Date createdTime);
}
